import 'package:flutter/cupertino.dart';
import 'package:client/common/event.dart';
import 'package:client/common/fun.dart';
import 'package:client/model/chat_msg_model.dart';

class ChatMsgProvider extends ChangeNotifier {
  //私聊消息
  Map<String, List<ChatMsgModel>> _infoMap = {};

  ChatMsgProvider() {
    bus.on(EventBusSet.chatMsg, (arg) {
      addMsg(arg as ChatMsgModel);
      bus.emit(EventBusSet.sound);
      notifyListeners();
    });
  }

  init() {
    _infoMap = {};
  }

  //todo init map
  addMsg(ChatMsgModel info) {
    print("chat msg 1");
    List<ChatMsgModel> list = _infoMap[info.talkId] ?? [];
    list.add(info);
    _infoMap[info.talkId] = list;

    print("info map");
    print(_infoMap);
  }

  getMsg(String key) {
    List<ChatMsgModel> list = _infoMap[key] ?? [];
    return list;
  }
}
